package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"goods_srv/goods"
)

type CreateGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGoodsLogic {
	return &CreateGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateGoodsLogic) CreateGoods(req *types.CreateGoodsRequest) (resp *types.Response, err error) {
	pay, err := l.svcCtx.GoodSrv.CreateGoods(l.ctx, &goods.CreateGoodsRequest{
		GoodsId:    1,
		GoodsTitle: req.GoodsTitle,
		GoodsPrice: req.GoodsPrice,
		GoodsStock: req.GoodsStock,
		GoodsCover: req.GoodsCover,
	})
	if err != nil {
		return &types.Response{
			Code: -1,
			Msg:  "服务器内部错误",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 0,
		Msg:  "创建成功",
		Data: map[string]interface{}{
			"pay": pay,
		},
	}, nil
}
